﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using SES.CMS.DO;

namespace SES.CMS.DAL
{
    public class cmsXuatXuDAL : BaseDAL
    {
        #region Public Methods
        public int Insert(cmsXuatXuDO objcmsXuatXuDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsXuatXu_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@XuatXu", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsXuatXuDO.XuatXu;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsXuatXuDO.MoTa;
            Sqlcomm.Parameters.Add(Sqlparam);


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsXuatXuDO objcmsXuatXuDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsXuatXu_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@XuatXuID", SqlDbType.Int);
            Sqlparam.Value = objcmsXuatXuDO.XuatXuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@XuatXu", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsXuatXuDO.XuatXu;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsXuatXuDO.MoTa;
            Sqlcomm.Parameters.Add(Sqlparam);




            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsXuatXuDO objcmsXuatXuDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsXuatXu_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@XuatXuID", SqlDbType.Int);
            Sqlparam.Value = objcmsXuatXuDO.XuatXuID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsXuatXu_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsXuatXuDO Select(cmsXuatXuDO objcmsXuatXuDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsXuatXu_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@XuatXuID", SqlDbType.Int);
            Sqlparam.Value = objcmsXuatXuDO.XuatXuID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["XuatXuID"]))
                    objcmsXuatXuDO.XuatXuID = Convert.ToInt32(dr["XuatXuID"]);
                if (!Convert.IsDBNull(dr["XuatXu"]))
                    objcmsXuatXuDO.XuatXu = Convert.ToString(dr["XuatXu"]);
                if (!Convert.IsDBNull(dr["MoTa"]))
                    objcmsXuatXuDO.MoTa = Convert.ToString(dr["MoTa"]);


            }
            return objcmsXuatXuDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsXuatXu_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsXuatXuDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsXuatXuDO objcmsXuatXuDO = new cmsXuatXuDO();
                    if (!Convert.IsDBNull(dr["XuatXuID"]))
                        objcmsXuatXuDO.XuatXuID = Convert.ToInt32(dr["XuatXuID"]);
                    if (!Convert.IsDBNull(dr["XuatXu"]))
                        objcmsXuatXuDO.XuatXu = Convert.ToString(dr["XuatXu"]);
                    if (!Convert.IsDBNull(dr["MoTa"]))
                        objcmsXuatXuDO.MoTa = Convert.ToString(dr["MoTa"]);

                    arrcmsXuatXuDO.Add(objcmsXuatXuDO);
                }
            }
            return arrcmsXuatXuDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsXuatXu_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion
    }


}
